package com.ad.backstage.controller;

import com.ad.backstage.service.IMerchantSystemService;
import com.ad.payload.dto.MerchantDto;
import com.ad.payload.dto.merchant.ItemDetailPageDto;
import com.ad.payload.dto.merchant.MerchantKeyValueAddDto;
import com.ad.payload.dto.merchant.MerchantKeyValueEditDto;
import com.ad.payload.model.MerchantImgDto;
import com.ad.payload.model.IdDto;
import com.ad.payload.model.ResultBean;
import com.ad.payload.model.UuidDto;
import com.ad.payload.vo.DetailKeyValue;
import com.ad.payload.vo.merchant.MerchantVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @author:dxgong
 * @日期 2021/4/19 18:14
 * @注释
 */
@RestController
@RequestMapping("MerchantController")
public class MerchantController {

    @Autowired
    private IMerchantSystemService iMerchantSystemService;


    /**
     * 查询详情列表
     *
     * @param itemDetailPageDto
     * */
    @PostMapping("/back/auth/queryDetailKeyValueList")
    public List<DetailKeyValue> queryDetailKeyValueList(@RequestBody @Valid ItemDetailPageDto itemDetailPageDto){
        return iMerchantSystemService.queryDetailKeyValueList(itemDetailPageDto);
    }



    /**
     * 添加商家详情
     *
     * @param merchantKeyValueAddDto
     * */
    @PostMapping("/back/auth/insertMerchantDetail")
    public Long insertMerchantDetail(@RequestBody @Valid MerchantKeyValueAddDto merchantKeyValueAddDto){
        return iMerchantSystemService.insertMerchantDetail(merchantKeyValueAddDto);
    }


    /**
     * 修改商家详情
     *
     * @param merchantKeyValueEditDto
     * */
    @PostMapping("/back/auth/updateMerchantDetail")
    public Long updateMerchantDetail(@RequestBody @Valid MerchantKeyValueEditDto merchantKeyValueEditDto){
        return iMerchantSystemService.updateMerchantDetail(merchantKeyValueEditDto);
    }


    /**
     * 删除详情
     *
     * @param idDto
     * */
    @PostMapping("/back/auth/deleteMerchantDetailById")
    public Long deleteMerchantDetailById(@RequestBody @Valid IdDto idDto){
        return iMerchantSystemService.deleteMerchantDetailById(idDto);
    }


    /**
     * 查询商家信息(商家端查询商家基础信息)
     *
     * @param uuidDto
     * */
    @PostMapping("/back/auth/queryMerchantInfoByUuid")
    public MerchantVo queryMerchantInfoByUuid(@RequestBody @Valid UuidDto uuidDto){
        return iMerchantSystemService.queryMerchantInfoByUuid(uuidDto);
    }

    /**
     * 更新商家信息(商家端查询商家基础信息，点击保存)
     *
     * @param merchantDto
     * */
    @PostMapping("/back/auth/updateMerchantByUuid")
    public Long updateMerchantByUuid(@RequestBody @Valid MerchantDto merchantDto){
        return iMerchantSystemService.updateMerchantByUuid(merchantDto);
    }

    /**
     * 商家端:基本信息(删除图片)
     *
     * @param merchantImgDto
     * */
    @PostMapping("/back/auth/delPic")
    public Long delPic(@RequestBody @Valid MerchantImgDto merchantImgDto){
        return iMerchantSystemService.delPic(merchantImgDto);
    }

    /**
     * 商家端:基本信息(上传图片)
     *
     * @param
     * */
    @RequestMapping("/back/auth/uploadPic")
    public ResultBean<String> uploadPic(@RequestParam(value="file",required=false) MultipartFile file, String flag, String uuid){

        String s = iMerchantSystemService.uploadPic(file, flag, uuid);

        return ResultBean.success(s);
    }

    /**
     * 维护封面图片宽高信息
     * @param uuid
     * @param width
     * @param height
     * @return
     */
    @PostMapping("/back/auth/updateImageWH")
    public Long updateImageWH(String uuid, Integer width, Integer height ){

       return iMerchantSystemService.updateImageWH(uuid, width, height);

    }


    /**
     * 根据Id查询商家一级目录名和二级目录名
     *
     * @param idDto
     * */
    @PostMapping("/back/auth/queryCategoryByMerchantId")
    public List<String> queryCategoryByMerchantId(@RequestBody @Valid IdDto idDto){
        return iMerchantSystemService.queryCategoryByMerchantId(idDto);
    }

}
